<?php
/**
 * Buildings View for RoomBooking Component
 * 
 * @version    1.0
 * @package    Joomla
 * @subpackage RoomBooking
 * @copyright (C) 2011 Giovanni Marzulli
 * @license	   GNU/GPL
 */
 
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
 
jimport( 'joomla.application.component.view' );
 
class RoomBookingViewBooking extends JView
{
	 /**
     * Booking view display method
     * @return void
     **/
	function display($tpl = null)
	{
		//get the booking
		$item		=& $this->get('Data');
		$isNew		= ($item->id < 1);
		$modelRooms = &$this->getModel('rooms');
		$rooms = $modelRooms->getRooms();

		$text = $isNew ? JText::_( 'New' ) : JText::_( 'Edit' );
		JToolBarHelper::title(   JText::_( 'BOOKING' ).': <small><small>[ ' . $text.' ]</small></small>' );
		JToolBarHelper::back();
		JToolBarHelper::save();
		JToolBarHelper::apply();
                
		if ($isNew)  {
			JToolBarHelper::cancel();
		} else {
			// for existing items the button is renamed `close`
			JToolBarHelper::cancel( 'cancel', 'Close' );
		}

		foreach($rooms as $room)
			$room->name=$room->id.' - '.$room->name;
		$this->assignRef('item', $item);
		$defaultOpt = new stdClass();
		$defaultOpt->id=null;
		$defaultOpt->name='- '.JText::_( 'SELROOM' ).' -';
		array_push($rooms, $defaultOpt);
		$this->assignRef('room', JHTML::_('select.genericlist',$rooms, 'id_room', 'class="inputbox" style="width:300px"','id','name',$this->item->id_room));
		
		/* //set bulding minTime, maxTime, we_opening if isn't new booking
		if ($isNew){
            $we_opening = true;
            $minTime = "00:00";
            $maxTime = "23:55";
             
        } else {
            $modelBuilding = &$this->getModel('building');
            $modelRoom = &$this->getModel('room');
            $id_building = $modelRoom->getIdBuildOfRoom($item->id_room);
            $times = $modelBuilding->getBuildOpenCloseTime($id_building);
            $minTime = $times->opening;
            $maxTime = $times->closing;
            $we_opening = $modelBuilding->getWEOpening($id_building);
        }
		 */

		$we_opening = true;
		$minTime = "00:00";
		$maxTime = "23:55";
	
		
		$db				=& JFactory::getDBO();
		$query= 'SELECT id, name FROM #__users;';
		$db->setQuery( $query );
		$users = $db->loadObjectList();
		
		foreach($users as $user)
			$user->name=$user->id.' - '.$user->name;
		
		$this->assignRef( 'users', $users );
		$this->assignRef( 'maxTime', $maxTime );
		$this->assignRef( 'minTime', $minTime );
		$this->assignRef( 'we_opening', $we_opening );
		
		parent::display($tpl);
	}
	
	
		
		
}
